package ge.home.app.globals;

import android.content.Context;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

import com.google.gson.Gson;

import java.util.List;

import ge.home.app.Utils;

/**
 * Created by bacho on 3/22/14.
 */
public class WebViewGrid extends WebView {
    Context context;
    private WebViewGridColumn[] columns;
    private List<?> data;

    public WebViewGrid(Context context, WebViewGridColumn[] columns, List<?> data) {
        super(context);
        this.columns = columns;
        this.data = data;
        this.context = context;
        getSettings().setJavaScriptEnabled(true);
        addJavascriptInterface(new WebAppInterface(), "javaFns");
        loadUrl("file:///android_asset/www/web_view_grid/grid.html");
    }


    private class WebAppInterface {
        @JavascriptInterface
        public String getData() {
            return new Gson().toJson(data);
        }

        @JavascriptInterface
        public String getColumns() {
            return new Gson().toJson(columns);
        }

        @JavascriptInterface
        public String showToast(String s) {
            Utils.showToast(context, s, 1000);
            return s;
        }
    }
}

